package com.example.checkcrypt;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.example.crypt.CryptToolFactory;
import com.example.crypt.CryptUtils;
import com.example.crypt.ICrypt;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


public class ViewActivity extends Activity {
    private String pDir = Environment.getExternalStorageDirectory() + "/com.foreveross.chameleon";
    private WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_activity3);

        webview = (WebView) findViewById(R.id.wv_web1);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setWebChromeClient(new WebChromeClient());
        webview.setWebViewClient(new WebViewClient());// 设置WebView客户端对象

        String encryptFilePath = getIntent().getStringExtra("path");
        ICrypt tool = CryptToolFactory.getInstance();
        try {
            InputStream fileStream = new FileInputStream(encryptFilePath);
            InputStream decryptStream = tool.decryptStream(fileStream);
            String data = CryptUtils.stream2String(decryptStream, "utf-8");
            webview.loadDataWithBaseURL("", data, "text/html", "utf-8", null);
        } catch(IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }
    }
}
